-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Update _models.py to handle Python 3.14
#2705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Thanks for this PR. I think it’s quite urgent since the current OpenAI API isn’t working on Python 3.14 because of this issue. |
|
Thanks for the PR but this isn't the correct fix, the places that read the |
Would you like for me to do so? |
🧩 The Root CauseStarting with Python 3.14, cast(CachedDiscriminatorType, union).__discriminator__ = detailsWith the error: AttributeError: 'typing.Union' object has no attribute '__discriminator__' and no __dict__ for setting new attributesThis behavior worked in |
✅ The Correct FixWe can’t store metadata on the Here’s how you can safely patch both OpenAI and Anthropic implementations: Step 1 – Create a global cacheAdd this near the top of the module (just after CachedDiscriminatorType is defined): import weakref
# Global cache since typing.Union objects are now immutable (Python 3.14+)
_DISCRIMINATOR_CACHE: "weakref.WeakKeyDictionary[type, DiscriminatorDetails]" = weakref.WeakKeyDictionary()Step 2 – Update
|
🧠 Why This Works
|
|
@RobertCraigie I updated my PR implementing the suggested plan. Let me know if this works for you. |
_models.py to handle Python 3.14
Changes being requested
Avoid tweaking Union API to make it works with Python 3.14
Additional context & links
Fixed #2704 to work properly with Python 3.14